package com.demo;

import com.demo.filter.MyFilter1;
import com.demo.filter.MyFilter2;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ServletComponentScan("com.demo.filter") //扫描MyFilter3
public class Config {
    //配置MyFilter1
    @Bean
    public FilterRegistrationBean myFilter1(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new MyFilter1());
        registrationBean.addUrlPatterns("/index");
        //控制执行顺序
        registrationBean.setOrder(1);
        return registrationBean;
    }

    //配置MyFilter2
    @Bean
    public FilterRegistrationBean myFilter2(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        //控制执行顺序
        registrationBean.setFilter(new MyFilter2());
        registrationBean.addUrlPatterns("/index");
        registrationBean.setOrder(2);
        return registrationBean;
    }
}
